<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function f(total, size, page, btnCount = 5) {
        const pageSize = Math.ceil(total / size)
        // show me your code
        const arr = [] // 能看到的页码集合
        arr.push(page)
        let left = page
        let right = page
        while (arr.length < btnCount) {
            left--
            right++
            if (left > 0) {
            arr.unshift(left)
            }
            if (right <= pageSize) {
            arr.push(right)
            }
        }
        return arr
        }
        // 在可能的情况下，让page处于正中间
        console.log(f(100, 10, 1, 5)) // ==> [1, 2, 3, 4, 5]
        console.log(f(100, 10, 7, 5)) // ==> [5, 6, 7, 8, 9]
        console.log(f(100, 10, 2, 5)) // ==> [1, 2, 3, 4, 5]
        console.log(f(100, 10, 5, 5)) // ==> [3, 4, 5, 6, 7]
        console.log(f(122, 10, 2, 7))
    </script>
</body>
</html>